package com.HooDee.netty.fourDemo;

import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.group.ChannelGroup;
import io.netty.channel.group.DefaultChannelGroup;
import io.netty.handler.timeout.IdleStateEvent;
import io.netty.util.concurrent.GlobalEventExecutor;

import java.util.UUID;

/**
 * Package: com.HooDee.netty.secondeDemo
 * Description：
 * Author: 蒋豪
 * Date:  2021.09.10 22:01
 * Modified By:
 */
public class MyChatServerHandler extends ChannelInboundHandlerAdapter{
    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
        if (evt instanceof IdleStateEvent) {
            IdleStateEvent event = (IdleStateEvent) evt;
            String eventType = null;
            switch (event.state()){
                    // 全部空闲
                case ALL_IDLE:
                    eventType = "读写空闲";
                    break;
                    // 读空闲
                case READER_IDLE:
                    eventType = "读空闲";
                    break;
                    // 写空闲
                case WRITER_IDLE:
                    eventType = "写空闲";
                    break;
            }
            System.out.println(ctx.channel().remoteAddress() + "超时事件：" + eventType);
            ctx.channel().close();
        }
    }
}
